﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CPPEI.WorkflowCore
{
    /// <summary>
    /// 工作流信息
    /// 如果流程有版本更新，那么code保持一次，但是id会变化，
    /// 通过code和版本号可以定位到历史的流程信息，
    /// 如果只通过code那么将定位到最新版本的流程信息。
    /// </summary>
    public class Workflow
    {
        /// <summary>
        /// 流程编号
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 流程id
        /// </summary>
        public Guid Id { get; private set; }

        /// <summary>
        /// 版本号
        /// </summary>
        public Version Version { get; set; }

        /// <summary>
        /// 是否每一步都备份业务数据，默认值为不备份
        /// </summary>
        public bool? IsBackingDataUpPerStep { get; set; }

        /// <summary>
        /// 起始活动
        /// </summary>
        public Activity Root { get; set; }

        private Workflow()
        {
            IsBackingDataUpPerStep = false;
        }

        /// <summary>
        /// 构造工作流，系统自动分配一个id
        /// </summary>
        /// <param name="code"></param>
        /// <param name="version"></param>
        public Workflow(string code, Version version)
            : base()
        {
            Id = Guid.NewGuid();
            this.Code = code;
            this.Version = version;
        }

        /// <summary>
        /// 构造工作流
        /// </summary>
        /// <param name="id"></param>
        /// <param name="code"></param>
        /// <param name="version"></param>
        public Workflow(Guid id, string code, Version version)
            : base()
        {
            Id = id;
            this.Code = code;
            this.Version = version;
        }
    }
}
